package com.it.oauth2.server;

import com.it.base.resposne.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * @program: auth2
 * @description: 资源服务controller
 * @author: Lefnmg
 * @create: 2018-11-23 10:16
 **/
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserServiceImpl userService;

    @RequestMapping("/getInfo")
    public JsonData getUser(HttpServletResponse response) throws IOException {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String username = (String) authentication.getPrincipal();
        User user = userService.findByName(username);
        return JsonData.ok().put("body", user);
    }
}
